﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using log4net;
using Mangox.Common;
using Mangox.Model.MangoxDB;

namespace Mangox.BLL.Applet
{
    public class AdminBLL
    {
        protected static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        private static string className = (new StackTrace()).GetFrame(1).GetMethod().ReflectedType.Name + "/";    

        public bool AddUserFeedback(M_Feedback model)
        {
            try
            {
                log.Info($"添加用户反馈信息：{JsonCommon.ToJson<M_Feedback>(model)}");

                using (MangoxDBEntities dbContext = new MangoxDBEntities())
                {
                    var temp = new M_Feedback()
                    {
                        Openid = model.Openid,
                        UID = model.UID,
                        Contact = model.Contact,
                        Message = model.Message,
                        SourceType = model.SourceType,
                        FeedbackType = model.FeedbackType,
                        CreateTime = DateTime.Now
                    };

                    dbContext.M_Feedback.Add(temp);
                    return dbContext.SaveChanges() > 0;
                }
            }
            catch (Exception ex)
            {
                log.Error(className + $"AddUserFeedback fail-{ex.ToString()}");
            }
            return false;
        }


    }
}
